const { app, ipcMain, BrowserWindow } = require('electron');
const path = require('path')
const { createSearchWindow } = require('./window_search.js')
const { createVideoCallWindow } = require('./window_call.js')

let main 

const createMainWindow = () => {
    main = new BrowserWindow({
        width: 985,
        height: 690,
        autoHideMenuBar: true,
        resizable: false,
        frame: false,
        webPreferences: {
           preload: path.join(__dirname, '../preload/preload.js') 
        }

    })

    main.loadURL('http://localhost:5173/main')
    // main.webContents.openDevTools()

    main.on('closed', () => {
        main = null
    })
}

app.on('ready', () => {
    // 搜索窗口IPC处理
    ipcMain.handle('web-search-invoke', (event, keyword) => {
        createSearchWindow(keyword)
    })
    // 视频通话窗口IPC处理
    ipcMain.handle('video-call-invoke', () => {
        createVideoCallWindow()
    })
})


module.exports = {
    createMainWindow
}   